<link rel="stylesheet" type="text/css" href="css/validationEngine.jquery.css">
<link rel="stylesheet" type="text/css" href="css/template.css">

<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="js/jquery.validationEngine.js"></script>
<script>
        jQuery(document).ready(function(){
            // binds form submission and fields to the validation engine
            jQuery("#formID").validationEngine();
        });
</script>

<script>
function Del_Info(str){
	var q=confirm('Bạn có chắc chắn muốn xóa hay không?');	
	if(q==true) 
		window.location=str;
	
}
</script>
<?php
$sql="SELECT substr( QUYEN,4, 1 ) as mq
FROM qldl_tai_khoan
WHERE ten_dang_nhap = '".$_SESSION['username']."'";
	$query = @mysql_query($sql,$conn);
	$row = @mysql_fetch_array($query);
	if($row['mq']==1){
	 @header('Location: index.php?page=ks'); 
	}
	else {
	echo  "<script>alert ('Bạn không có quyền truy cập trang này!')</script>"; 
	echo "<meta http-equiv='refresh' content='0;url= index.php'>";
	}
?>
<?php
			

			$sql="select max( MA_KHACH_SAN) from  qldl_khach_san"; 
			$result=mysql_query($sql); 
			$kq=mysql_fetch_array($result); 
			$ma=$kq[0]+1; 
				?>
<div class="cpanel-right-tttk">
  <div id="panel-sliders" class="pane-sliders">
    <div class="panel">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style=" padding:10px;">
  <thead>
        <tr style=" padding-bottom:10px;">
        <th colspan="3" align="left" style="padding-bottom:10px;">QUẢN LÍ DANH MỤC KHÁCH SẠN</th>
        </tr> 
        </thead>   
  <tr valign="top" style="padding:5px;">
    <td width="45%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
      <form action="" name="formID" id="formID" method="post" enctype="multipart/form-data">
      <table width="98%" border="1" bordercolor="#666666" class="adminlist_tt">
        <thead>
          <tr>
            <th colspan="3"> Thông tin thêm khách sạn</th>
          </tr>
        </thead>
        <tbody>
    
          <tr>
            <td>Mã thành phố</td>
            <td colspan="2">
              <select id="chon_ttp" name="chon_ttp" class="validate[required]">
						<?php 
							$sql_ttp="select * from qldl_tinh_thanh_pho order by MA_TP asc";
							$query_ttp = @mysql_query($sql_ttp,$conn);	
							if($query_ttp)
							echo "<option value='' selected>Chọn tỉnh/thành phố</option>";
							while($row_ttp = @mysql_fetch_array($query_ttp)){
						?>  
						<option value="<?php echo $row_ttp['MA_TP'];?>"><?php echo $row_ttp['THANH_PHO'];?></option>
							<?php }?> 
					</select>
            	</td>
          </tr>
          <tr>
            <td height="26">Khách sạn</td>
            <td colspan="2">
              <label for="txt_khach_san"></label>
              <input type="text" class="validate[required] text-input" name="txt_khach_san" id="txt_khach_san" />
            </td>
          </tr>
          <tr>
            <td>Tiêu chuẩn</td>
            <td colspan="2"><input type="text" class="validate[required] text-input" name="txt_tieu_chuan" id="txt_tieu_chuan" /></td>
          </tr>
          <tr>
            <td>Chi tiết</td>
            <td colspan="2">
              <textarea name="area" id="area" style="height:100px; width:100%;"></textarea>
             </td>
          </tr>
   <tr>
                  <td>Tóm tắt</td>
                  <td><label for="textarea_tttt"></label>
                    <textarea name="area_ttks" id="area_ttks" style="height:100px; width:100%;" ></textarea></td>
                  </tr>
                <tr>
          <tr>
            <td height="37">Hình ảnh</td>
            <td colspan="2">
              <label for="txt_hinh_anh"></label>
              <input type="file" name="file_up" />
            </td>
          </tr>
          <tr>
            <td colspan="3">
              <input type="submit" name="btn_add_ks" id="btn_add_ks" value="Lưu" />
              <input type="reset" name="Reset" id="button" value="Hủy">
            <?php
				  if(isset($_POST['btn_add_ks'])){
					$maks = $_POST['txt_ma_khach_san'];
					$ttp = $_POST['chon_ttp'];
					$tks = $_POST['txt_khach_san'];
					$ttks = $_POST['area_ttks'];
					$tc = $_POST['txt_tieu_chuan'];
					$ct = $_POST['area'];
					  if ($_FILES["file_up"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file_up"]["error"] . "<br />";
    }
  else
    {
    if (file_exists("khach_san/upload/news/" . $_FILES["file_up"]["name"]))
      {
      echo $_FILES["file_up"]["name"] . " da ton tai file tren server. ";
      }
    else
      {  
      move_uploaded_file($_FILES["file_up"]["tmp_name"],
      "khach_san/upload/news/" . $_FILES["file_up"]["name"]);	
	  $link = "khach_san/upload/news/" . $_FILES["file_up"]["name"];
	   
      }
	}
		
					$sql = "INSERT INTO qldl_khach_san VALUES('$ma','$ttp','$tks','$tc','$ct','$link','$ttks')";
	  				$query = @mysql_query($sql,$conn);
						if($query)echo "<script>alert ('Thêm thông tin thành công.')</script>";	
						else echo "<script>alert ('Thêm không thành công!')</script>";
					
					
					}
	  ?>
            </td>
          </tr>
          
        </tbody>
      </table>
      </form>
    </div></td>
    <td width="60%"><div style=" padding:0px; border-top: medium none; border-bottom: medium none; overflow: hidden; height: auto; width:100%" align="left">
      <table width="100%" border="1" bordercolor="#666666" class="adminlist_tt">
        <thead>
          <tr>
            <th colspan="5" align="center"> Danh sách điểm du lịch</th>
            <?php include('khach_san/del.php'); ?>
          </tr>
        </thead>
        <tbody>
        <form action="" method="post" name="form_view" id="form_view">
          <tr>
            <td width="63" align="center">Mã khách sạn</td>
            <td width="107" align="center">Mã thành phố</td>
            <td width="165" align="center">Khách sạn</td>
            <td width="81" align="center">Tiêu chuẩn</td>
            <td width="66">Cập nhật</td>
          </tr>
          
          <?php
				$stt=0;
	$sql="select * from qldl_khach_san";
	$query = @mysql_query($sql,$conn);	
	if(!$query) echo "Query error to display.";
	else while($row = @mysql_fetch_array($query)){
		$stt++;
			?>	 
                <tr>
                  <td><?php echo $row['MA_KHACH_SAN'];?></td>
                  <td><?php echo $row['MA_TP'];?></td>
                  <td><?php echo $row['KHACH_SAN'];?></td>
                  <td><?php echo $row['TIEU_CHUAN'];?></td>
                  <td><a href="index.php?page=id_edit_ks&amp;id_edit_ks=<?php echo $row['MA_KHACH_SAN'];?>&amp;id_ttp=<?php echo $row['MA_TP'];?>">Sửa</a> || 
                  <a onclick="Del_Info('index.php?page=ks&amp;id_del_ks=<?php echo $row['MA_KHACH_SAN'];?>&amp;id_photo=<?php echo $row['HINH_ANH'];?>');" href="#">Xóa</a></td>
                </tr>
				<?php	}
                ?>
                </form>
        </tbody>
      </table>
    </div></td>
  </tr>
</table>
   </div>
  </div>
</div>